﻿using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.Sys;
using JESAI.Application.Abstractions.Sys.Dtos;
using JESAI.Application.Abstractions.Sys.Querys;
using JESAI.Application.Service.Sys;
using JESAI.AutoMapper.ObjectMapping;
using JESAI.Framework.Filters;
using JESAI.Platform.WebApi.Vos.Sys;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace JESAI.Platform.WebApi.Controllers.Sys
{
    [ApiController]
    [Route("api/v1/[controller]/[action]")]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class FormDataSourceController : ControllerBase
    {
        private readonly IFormDataSourceService _formDataSourceService;

        public FormDataSourceController(IFormDataSourceService formDataSourceService)
        {
            _formDataSourceService = formDataSourceService;
        }

        /// <summary>
        /// 获取表单映射数据源列表
        /// </summary>
        /// <param name="formId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BaseOutput<List<FormDataSourceRefResponse>>> GetFormColumnRefDataSourceList([FromQuery] string formId)
        {
            var formColumnRefDataSourceList = await _formDataSourceService.GetFormColumnRefDataSourceList(formId);
            return new BaseOutput<List<FormDataSourceRefResponse>>() { Data = formColumnRefDataSourceList.MapTo<List<FormDataSourceRefResponse>>() };
        }

        [HttpPost]
        public async Task<BaseOutput> SaveOrUpdateFormDataSourceRef([FromBody] List<FormDataSourceRefInput> formDataSourceRefInputs)
        {
            await _formDataSourceService.SaveOrUpdateFormDataSourceRef(formDataSourceRefInputs);
            return new BaseOutput();
        }
    }
}
